﻿using Core;
using System;
using UnityEngine;
#if UNITY_WX
using WeChatWASM;
#endif

public class SystemMono : MonoBehaviour
{
    public EResMode ResMode;
    public ESysGame StartupProject;
    public TblGame TblGame;

    void Awake()
    {
        DontDestroyOnLoad(gameObject);
        Global.ResMode = ResMode;

        LeanTouch.SetImpl(new LeanTouchImple());
        Mint.SetImpl(new MintImple());

        Utils.Camera.SetImpl(new CameraImple());

        Context.Awake(TblGame, this, StartupProject);
        Context.SetContext(typeof(s_common.Launch));

        Context.Start();
#if UNITY_WX
        WX.OnShow(OnShow);
        WX.OnHide(OnHide);
#endif
    }


#if UNITY_WX
    private void OnShow(OnShowListenerResult result)
    {
        Debug.LogError(result.ToString());

    }
    private void OnHide(GeneralCallbackResult result)
    {
        Debug.LogError(result.ToString());
        Messenger.Post(GlobalEvent.OnDestroy);
    }
#endif

    private void Update()
    {
        Context.Update();
    }

    private void LateUpdate()
    {
        Context.LateUpdate();
    }

    private void FixedUpdate()
    {
        Context.FixedUpdate();
    }

    private void OnDestroy()
    {
        Context.Destroy();
    }
}